package npr.gui;

import processing.core.PFont;

public class CheckBox extends GUI{

    private boolean checked;
    private String text;
    private float textPos;
    private Field checkBox;


    public CheckBox(int xpos, int ypos, String text, boolean checked){
	this(xpos, ypos, null, defaultFontSize, text, checked);
    }

    public CheckBox(int xpos, int ypos, PFont font, int fontSize, String text, boolean checked){
        
	super(xpos, ypos, 12, 12, font, fontSize);
	this.text= text;
	this.textPos= labelXPos(text);
        this.checked= checked;
	checkBox= new Field(xpos, ypos, height, height);
    }


    public boolean checked(){

	return checked;
    }

    protected void mousePressed(int x, int y){

	super.mousePressed(x, y);
	if(checkBox.inside(x, y)){
	    checked=!checked;
	}
    }

    public void draw(){

	if(display){        
	    parent.hint(DISABLE_DEPTH_TEST);
	    parent.textFont(font, fontSize);
	    parent.fill(fontColor);
	    parent.text(text, xpos-textPos,  ypos+height/2+font.ascent()*fontSize*0.5f);
	    checkBox.draw();
	    if (checked){
		parent.smooth();
		parent.strokeWeight(2);
		parent.stroke(fontColor);
		parent.line(xpos+3, ypos+height/2, xpos+width/2, ypos+height-3);
		parent.line(xpos+width/2, ypos+height-3, xpos+width-3, ypos+2);
		parent.strokeWeight(1);
		parent.noSmooth();
	    }
	    parent.hint(ENABLE_DEPTH_TEST);
	}
    }
}